import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import * as path from 'path';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';

// https://vitejs.dev/config/
export default defineConfig({

  plugins: [
    vue(),
    AutoImport({
      imports: ['vue'],
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],

  resolve: {
    // 设置别名
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  // 新增
  server: {
    cors: true, // 默认启用并允许任何源
    open: false, // 默认打开浏览器
    port: 3000, // 访问的端口号
    // host: '0.0.0.0', // 访问的地址
    proxy: {
      '/api': {
        target: 'http://175.178.155.19:3000',
        changeOrigin: true, // 是否允许跨域代理
        rewrite: (path) => path.replace(/^\/api/, ''), // 重定向地址
      },
    },
  },
});
